package render
{
	import mx.binding.utils.BindingUtils;
	import mx.containers.Canvas;
	import mx.controls.DataGrid;
	import mx.controls.dataGridClasses.DataGridColumn;

	public class ListRender extends Canvas implements DynamicDataRenderer
	{
		private var _rootURI:String;
		private var _fetcherFunction:Function;
		private var maxSize:int = 500;
		private var dataGrid:DataGrid;
		
		public function ListRender()
		{
			super();
			dataGrid = new DataGrid();
			BindingUtils.bindProperty(dataGrid,"width",this,"width");
			BindingUtils.bindProperty(dataGrid,"height",this,"height");
			var col1:DataGridColumn = new DataGridColumn("predicate");
			var col2:DataGridColumn = new DataGridColumn("object");
			dataGrid.columns.push( col1);
			dataGrid.columns.push( col2);
			this.addChild(dataGrid);			
		}
		private function reInit():void
		{
			_fetcherFunction.call(this,fetchHandler,_rootURI,0,maxSize);
		}
		private function fetchHandler(array:Array):void
		{
			var result:Array = new Array();
			
			for each( var triple:Triple in array){
				if(triple.subject == _rootURI){
					result.push({predicate: format(triple.predicate),object:format(triple.object)});
				}
			}
			dataGrid.dataProvider = result;
		}
		public function format(string:String):String
		{
			return string;
		}
		public function set fetcherFunction(func:Function):void
		{
			_fetcherFunction = func;
		}
		public function set rootURI(uri:String):void
		{
			_rootURI = uri;
			reInit();
		}
		
		
	}
}